using System;
using System.Drawing;
using System.Windows.Forms;

using Engine;
using Engine.Rendering;

namespace Test
{
    public class RenderSimulation : RenderWindow
    {
        public Model brum;

        public RenderSimulation() : base("Render Simulation")
        {
            MeshManager.Instance.LoadMesh("Car", "data/model/car.x", MeshType.MT_MODEL);

            // Initiate DirectX
            InitDevice(800, 600, false);

            // Setup Lights
            device.Lights[0].Type = Microsoft.DirectX.Direct3D.LightType.Directional;
            device.Lights[0].Diffuse = Color.White;
            device.Lights[0].Ambient = Color.White;
            device.Lights[0].Direction = new Microsoft.DirectX.Vector3(-0.5f, -1f, 0);
            device.Lights[0].Enabled = true;

            // Setup skybox
            skybox = new Skybox("data/model/skybox.x");
            skybox.Init(device);

            // Setup brum
            brum = new Model("Brum", "Car");
            brum.Translate(5, 0, 0);

            // Setup camera node
            Component cnode = new Component("Camera Node");
            cnode.SetParent(brum);

            // Setup camera
            Camera = new Camera("Camera");
            Camera.SetParent(cnode);
            Camera.Translate(0, 5, 20);
            Camera.Yaw(180);
            Camera.Pitch(20);
            Camera.Frustum.Far = 500f;

            AddRenderable(brum);
            AddRenderable(new Model("Piet", "Car"));

            AddDiagnostic(brum);
            AddDiagnostic(camera);

            // Attach event handlers
            KeyPress += new KeyPressEventHandler(window_KeyPress);
        }

        public static void Main(String[] args)
        {
            Application.Run(new RenderSimulation());
        }

        // Event handlers
        public void window_KeyPress(object sender, KeyPressEventArgs e)
        {
            switch (e.KeyChar)
            {
                // Translations
                case 'w': brum.Translate(0, 0, -1.0f);
                    break;
                case 's': brum.Translate(0, 0, 1.0f);
                    break;
                case 'a': brum.Translate(1.0f, 0, 0);
                    break;
                case 'd': brum.Translate(-1.0f, 0, 0);
                    break;

                case 'l': brum.LookAt(0, 0, 0);
                    break;

                case 'q': this.Dispose();
                    break;
            }
        }
    }
}
